package com.example.model.vo;

public class ResultVO<T> {

    private int code;
    private String msg;
    private T data;

    public ResultVO(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 统一返回内容
     * 错误码设计规范：
     * 1xx - 信息性状态码
     * 2xx - 成功状态码
     * 3xx - 重定向状态码
     * 4xx - 客户端错误
     * 5xx - 服务器错误
     */

    // ====== 2xx 成功状态码 ======
    public static ResultVO SUCCESS = new ResultVO(200, "请求成功", "操作成功");
    public static ResultVO CREATED = new ResultVO(201, "创建成功", "资源创建成功");
    public static ResultVO ACCEPTED = new ResultVO(202, "请求已接受", "请求正在处理中");

    // ====== 3xx 重定向状态码 ======
    public static ResultVO REDIRECT = new ResultVO(302, "临时重定向", "请求重定向到新地址");

    // ====== 4xx 客户端错误 ======
    // 40xxx - 通用客户端错误
    public static ResultVO BAD_REQUEST = new ResultVO(400, "请求无效", "请求参数错误或不完整");
    public static ResultVO UNAUTHORIZED = new ResultVO(401, "未授权", "请先进行身份认证");
    public static ResultVO FORBIDDEN = new ResultVO(403, "禁止访问", "没有操作权限");
    public static ResultVO NOT_FOUND = new ResultVO(404, "资源不存在", "请求的资源不存在");
    public static ResultVO METHOD_NOT_ALLOWED = new ResultVO(405, "方法不允许", "请求方法不支持");
    public static ResultVO TOO_MANY_REQUESTS = new ResultVO(429, "请求过于频繁", "请稍后再试");
    public static ResultVO USER_NOT_EXIST = new ResultVO(40105, "用户不存在", "请检查用户信息");


    // 401xx - 认证相关错误
    public static ResultVO TOKEN_EXPIRED = new ResultVO(40101, "Token已过期", "请重新登录");
    public static ResultVO TOKEN_INVALID = new ResultVO(40102, "Token无效", "无效的认证信息");
    public static ResultVO TOKEN_EMPTY = new ResultVO(40103, "Token缺失", "请提供认证信息");
    public static final ResultVO SIGN_INVALID = new ResultVO(40104, "签名无效", "请检查签名信息");

    // 402xx - 参数校验错误
    public static ResultVO PARAM_EMPTY = new ResultVO(40201, "参数缺失", "必要参数未提供");
    public static ResultVO PARAM_ERROR = new ResultVO(40202, "参数错误", "参数格式或内容不正确");
    public static ResultVO PARAM_TYPE_ERROR = new ResultVO(40203, "参数类型错误", "参数类型不匹配");

    // 403xx - 业务规则错误
    public static ResultVO NAME_ERROR = new ResultVO(40301, "姓名错误", "请输入正确的姓名");
    public static ResultVO IDNUMBER_LENGTH_ERROR = new ResultVO(40302, "身份证号码长度错误", "请输入18位身份证号码");
    public static ResultVO SALARY_ERROR = new ResultVO(40303, "工资金额错误", "请输入有效的工资金额");
    public static ResultVO SEX_ERROR = new ResultVO(40304, "性别错误", "请选择正确的性别");
    public static ResultVO AGE_ERROR = new ResultVO(40305, "年龄错误", "请输入有效的年龄");
    public static ResultVO USER_TYPE_ERROR = new ResultVO(40306, "用户类型错误", "不支持的用户类型");

    // ====== 5xx 服务器错误 ======
    // 500xx - 系统级错误
    public static ResultVO INTERNAL_ERROR = new ResultVO(50000, "系统内部错误", "服务器内部错误");
    public static ResultVO SERVICE_UNAVAILABLE = new ResultVO(50001, "服务不可用", "系统维护中");
    public static ResultVO DB_ERROR = new ResultVO(50002, "数据库错误", "数据库操作失败");
    public static ResultVO AI_ERROR = new ResultVO(50003, "AI服务错误", "AI服务调用失败");
    public static ResultVO CONTRACT_ERROR = new ResultVO(50004, "智能合约错误", "智能合约执行失败");

    // 501xx - 业务处理错误
    public static ResultVO QUERY_EMPTY = new ResultVO(50101, "查询结果为空", "未找到符合条件的数据");
    public static ResultVO QUERY_EXISTS = new ResultVO(50102, "数据已存在", "请勿重复操作");
    public static ResultVO AMOUNT_NOT_ENOUGH = new ResultVO(50103, "余额不足", "账户余额不足");

    // 502xx - 用户账户相关错误
    public static ResultVO ACCOUNT_EXIST = new ResultVO(50201, "账户已存在", "该账户已被注册");
    public static ResultVO ACCOUNTS_NOT_EXIST = new ResultVO(50202, "账户不存在", "请检查账户信息");
    public static ResultVO PASSWORD_ERROR = new ResultVO(50203, "密码错误", "请输入正确的密码");
    public static ResultVO ID_NUMBER_IS_EXIST = new ResultVO(50204, "身份证已注册", "该身份证号已被使用");

    // 503xx - 组织机构相关错误
    public static ResultVO COMPANY_NOT_EXIST = new ResultVO(50301, "公司不存在", "请检查公司信息");
    public static ResultVO SPONSOR_EXIST = new ResultVO(50302, "工作单位已存在", "该工作单位已注册");
    public static ResultVO SPONSOR_NOT_EXIST = new ResultVO(50303, "工作单位不存在", "请检查工作单位信息");
    public static ResultVO Bureaus_NAME_EXIST = new ResultVO(50304, "社保局已存在", "该社保局名称已被注册");

    // 504xx - 区块链相关错误
    public static ResultVO ADDRESS_INVALID = new ResultVO(50401, "地址无效", "无效的区块链地址");
    public static ResultVO SENDER_ADDRESS_ERROR = new ResultVO(50402, "发送地址错误", "请检查发送方地址");
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
